package com.mg;

import org.junit.Test;

/**
 *
 */
public class LinkedListTest {

    @Test
    public void tableSizeFor() {

        int cap = 16;
        int MAXIMUM_CAPACITY = 1 << 30;

        //>>>：无符号右移，忽略符号位，空位都以0补齐

        // 扩容门槛为传入的初始容量往上取最近的2的n次方
        int n = cap - 1;
        n |= n >>> 1;
        n |= n >>> 2;
        n |= n >>> 4;
        n |= n >>> 8;
        n |= n >>> 16;
        int m = (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
        System.out.println(m);
    }

    /**
     * 测试右移 >>>
     */
    @Test
    public void testRightSheft() {
        int n = -10;
        System.out.println(Integer.toBinaryString(n));
        //>>>：无符号右移，忽略符号位，空位都以0补齐
        System.out.println(Integer.toBinaryString(n>>> 1));
        System.out.println(n >>> 2);
    }
}